<script lang="ts" setup>
import { ref } from 'vue';
import { ElMessage } from 'element-plus';

// 登录表单数据
const loginForm = ref({
    username: '',
    password: ''
});

// 固定的用户名和密码
const VALID_USERNAME = 'admin';
const VALID_PASSWORD = 'Hanyun@654';

// 登录处理
const handleLogin = () => {
    if (loginForm.value.username === VALID_USERNAME && loginForm.value.password === VALID_PASSWORD) {
        // 登录成功，设置本地存储
        localStorage.setItem('isLoggedIn', 'true');
        // 跳转到主页
        window.location.href = import.meta.env.BASE_URL;
        ElMessage.success('登录成功');
    } else {
        ElMessage.error('用户名或密码错误');
    }
};
</script>

<template>
    <div class="login-container">
        <div class="login-box">
            <h2 class="login-title">数据洞察智能体平台</h2>
            <div class="login-form">
                <div class="form-item">
                    <label>用户名</label>
                    <el-input v-model="loginForm.username" placeholder="请输入用户名" />
                </div>
                <div class="form-item">
                    <label>密码</label>
                    <el-input v-model="loginForm.password" type="password" placeholder="请输入密码"
                        @keyup.enter="handleLogin" />
                </div>
                <div class="form-item">
                    <el-button type="primary" class="login-button" @click="handleLogin">登录</el-button>
                </div>
                <!-- <div class="login-tips">
                    <p>默认账号: admin</p>
                    <p>默认密码: 123456</p>
                </div> -->
            </div>
        </div>
    </div>
</template>

<style scoped>
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #f5f7fa;
}

.login-box {
    width: 400px;
    padding: 40px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.login-title {
    text-align: center;
    margin-bottom: 30px;
    color: #409eff;
    font-size: 24px;
}

.login-form {
    margin-top: 20px;
}

.form-item {
    margin-bottom: 20px;
}

.form-item label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}

.login-button {
    width: 100%;
    padding: 12px 0;
    margin-top: 10px;
}

.login-tips {
    margin-top: 20px;
    color: #999;
    font-size: 13px;
    text-align: center;
}

.login-tips p {
    margin: 5px 0;
}
</style>